import random
import time

def guess_number_game():
    # 生成1到100之间的随机数
    secret_number = random.randint(1, 100)
    attempts = 0
    max_attempts = 10  # 最多10次猜测机会
    
    print("欢迎来到猜数字游戏！")
    print(f"我已经想好了一个1到100之间的数字，你有{max_attempts}次机会猜出它。")
    time.sleep(1)
    
    while attempts < max_attempts:
        # 计算剩余次数
        remaining = max_attempts - attempts
        
        # 获取玩家输入并验证
        try:
            guess = input(f"请输入你的猜测（剩余{remaining}次机会）：")
            guess = int(guess)
        except ValueError:
            print("请输入一个有效的整数！")
            continue
        
        attempts += 1
        
        # 判断猜测结果
        if guess < secret_number:
            print("太小了！再试一次。")
        elif guess > secret_number:
            print("太大了！再试一次。")
        else:
            print(f"恭喜你！你猜对了！答案就是{secret_number}。")
            print(f"你用了{attempts}次就猜到了正确答案。")
            return
    
    # 如果用完了所有机会仍未猜对
    print(f"很遗憾，你已经用完了所有{max_attempts}次机会。")
    print(f"正确答案是{secret_number}。")

# 启动游戏
if __name__ == "__main__":
    guess_number_game()
